const {
  override,
  addWebpackAlias,
  addWebpackModuleRule,
  fixBabelImports,
  addLessLoader
} = require('customize-cra');

const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  webpack: override(
    addWebpackAlias({
      '@': resolve('src'),
    }),
    addWebpackModuleRule({
      // test: /\.(eot|woff2?|ttf|svg)$/,
      test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
      exclude: resolve("src/icons"),
      use: [
        {
          loader: "url-loader",
          options: {
            name: 'static/imgs/[name].[hash:7].[ext]',
            limit: 10000,
          }
        }
      ]
    }),
    addWebpackModuleRule({
      test: /\.svg$/,
      loader: "svg-sprite-loader",
      include: resolve("src/icons"),
      options: {
        symbolId: "icon-[name]"
      }
    }),
    // https://github.com/ant-design/ant-design/issues/23624
    fixBabelImports('import', {
      libraryName: 'antd',
      libraryDirectory: 'es',
      style: 'css',
    }),
    addLessLoader({
      lessOptions: {
        javascriptEnabled: true,
        modifyVars: {
          '@primary-color': '#1DA57A'
        }
      }
    })
  ),
  paths: function (paths, env) {
    // ...add your paths config
    console.log('env', env)
    console.log('paths', JSON.stringify(paths))
    console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
    return paths;
  },
};
